package org.vacoor.nothing.security;

import com.google.common.collect.Lists;
import org.vacoor.nothing.common.reflect.TypeReference;
import org.vacoor.nothing.common.reflect.TypeResolver;

import java.lang.reflect.Array;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;

/**
 */
public class Arrays2 {

    public static int[] push(int[] array, int... elements) {
        int len = array.length;
        int eLen = elements.length;
        int[] newArray = Arrays.copyOf(array, len + eLen);

        for (int i = 0; i < eLen; i++) {
            newArray[len + i] = elements[i];
        }
        return newArray;
    }

    public static <E> E[] asArray(Collection<E> collection) {
        Class<? extends Callable<E>> type = new Callable<E>() {
            @Override
            public E call() throws Exception {
                return null;
            }
        }.getClass();
        System.out.println(TypeResolver.resolveActualTypeArguments(type, Collection.class));
        return null;
    }

    public static <E> E[] create(Class<E> elementType, int length) {
        return (E[]) Array.newInstance(elementType, length);
    }

    public static <T, S extends T> T[] push(T[] array, S... elements) {
        return array;
    }

    public static void main(String[] args) {
        /*
        int[] array = new int[0];
        array = Arrays2.push(array, 1);
        System.out.println(Arrays.toString(array));
        */
        List<String> a = Lists.newArrayList("XX");
        String[] xxes = Arrays2.asArray(a);
    }
}
